Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate pattern in favour of select in data_rename() #568

Merged
merged 20 commits into from
Dec 2, 2024

Conversation

etiennebacher
Copy link
Member

Close #566

R/text_format.R Outdated Show resolved Hide resolved
R/data_rename.R Outdated Show resolved Hide resolved
R/data_rename.R Show resolved Hide resolved
R/data_rename.R Outdated Show resolved Hide resolved
R/data_rename.R Show resolved Hide resolved
@strengejacke
Copy link
Member

The docs are a bit messed up at the moment:
{8EA7D9FD-CD68-4199-9999-0FEAF59F2AC0}

pattern is not deprecated for data_addprefix() (and suffix), and the docs for select (for data_addprefix() is actually for the pattern argument. The select argument in data_addprefix() uses the normal select-helper functionality. We either have to split data_addprefix() and data_addsuffix() from data_rename() to have two different help-files, or, if we really use the classical select in data_rename(), we don't have to change much in the docs. Just pattern only refers to data_addprefix() and that's it.

@etiennebacher
Copy link
Member Author

I think it makes sense to split docs between data_rename() in one page and data_addprefix() and data_addsuffix() in another. We can use @seealso to redirect to the other.

@strengejacke
Copy link
Member

Changes look good to me, I think it's just that tests need to be updated?

@etiennebacher
Copy link
Member Author

Yes I'm just waiting to see if we keep using column indices as valid replacements or not.

@strengejacke
Copy link
Member

Yes I'm just waiting to see if we keep using column indices as valid replacements or not.

I'd say we can remove this. It's easy to do colnames(x) <- seq_len(ncol(x)). We also don't use this type of replacement in any easystats-packages, if I haven't missed something.

@etiennebacher etiennebacher merged commit 0512212 into main Dec 2, 2024
22 checks passed
@etiennebacher etiennebacher deleted the deprecate-pattern branch December 2, 2024 10:45
@strengejacke
Copy link
Member

@etiennebacher I think I updated all packages in easystats that are affected by the new data_rename() changes. One thing I thought of was if we could/should keep the safe argument? Based on its value, we could set ifnotfound either to "warn" or "error", which should restore the previous behaviour. WDYT?

@etiennebacher
Copy link
Member Author

Right, now that we have ifnotfound we can do that, I'll open a PR

@etiennebacher
Copy link
Member Author

etiennebacher commented Dec 3, 2024

Actually it's not that easy because even if .select_nse() only warns, it doesn't include the unknown column name in the output. So for instance, if we do data_rename(iris, "FakeCol", "length") then .select_nse() returns character(0) and therefore we still error with There are more names in 'replacement' than in 'select'.

@strengejacke
Copy link
Member

Hm, true. Or, if safe = TRUE, we just skip this check as well? Meaning that safe will "intersect" all valid columns and their replacement values, and use that for rename. Any values in replacement without a match in select will be ignored. For safe = FALSE, we set ifnotfound = "error", and include the check for unequal lengths.

@etiennebacher
Copy link
Member Author

etiennebacher commented Dec 3, 2024

Or, if safe = TRUE, we just skip this check as well? Meaning that safe will "intersect" all valid columns and their replacement values, and use that for rename.

But we don't know the position of the wrong column names since it's not returned by .select_nse(). For instance if we do this:

data_rename(iris, c("Sepal.Length", "foo"), c("rep1", "rep2"))

then .select_nse() returns "Sepal.Length", but how do we know which replacement we should use? We can't compare to the original select since it could be regex() for instance. I don't see a good way to enable this. Is the safe argument really important?

@strengejacke
Copy link
Member

Ok, agree. Then we don't need to change anything and deprecate the safe argument, as we now do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use select instead of pattern in data_rename()?
2 participants